"use strict";

const Base = require("../base");
const LANG = require("../../language"); // 插件语言库
const LANG_T = antSword["language"]["toastr"]; // 通用通知提示
class ShellcodeLoader extends Base {
  createForm() {
    let self = this;
    let editor = null;
    // 初始化编辑器
    editor = ace.edit(self.cellA.cell.lastChild);
    editor.$blockScrolling = Infinity;
    editor.setTheme("ace/theme/tomorrow");
    editor.session.setUseWrapMode(true);
    editor.session.setWrapLimitRange(null, null);

    editor.setOptions({
      fontSize: "14px",
      enableBasicAutocompletion: true,
      enableSnippets: true,
      enableLiveAutocompletion: true,
    });
    const inter = setInterval(editor.resize.bind(editor), 200);
    self.win.win.attachEvent("onClose", () => {
      clearInterval(inter);
      return true;
    });
    self.editor2 = editor;
  }
  exploit() {
    let self = this;
    self.core = this.top.core;
    let shellcode = self.editor2.session.getValue();
    self.parammode = 2;
    let args = {
      shellcode: shellcode,
    };

    let data = this.genPayload(args);

    self.core
      .request(data)
      .then((_ret) => {
        let res = antSword.unxss(_ret["text"], false);
        if (res === "") {
          res = "output is empty.";
        }
        switch (self.shelltype) {
          case "aspx":
            self.editor.session.setValue(res);
            self.editor.setReadOnly(true);
            break;
        }
        toastr.success(LANG["success"], LANG_T["success"]);
      })
      .catch((e) => {
        console.log(e);
        toastr.error(e.constructor === Object?JSON.stringify(e):e, "Error");
      });
  }
}
module.exports = ShellcodeLoader;
